<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>员工信息管理系统 - 编辑员工</title>
    <link rel="stylesheet" type="text/css" href="../css/style.css">
</head>
<body>
<header>
    <div class="logo">员工信息管理系统</div>
    <nav>
        <ul>
            <li><a href="../dashboard.jsp">仪表盘</a></li>
            <li class="active"><a href="list.jsp">员工管理</a></li>
        </ul>
    </nav>
    <div class="user-info">
        <span>欢迎, ${user.username}</span>
        <a href="../LogoutServlet" class="logout-btn">退出</a>
    </div>
</header>

<main>
    <div class="content-container">
        <div class="content-header">
            <h2>编辑员工</h2>
            <a href="../EmployeeServlet?action=list" class="btn secondary">返回列表</a>
        </div>

        <div class="form-container">
            <form action="../EmployeeServlet?action=update" method="post">
                <input type="hidden" name="id" value="${employee.id}">

                <% if (request.getAttribute("error") != null) { %>
                <div class="error-message"><%= request.getAttribute("error") %></div>
                <% } %>

                <div class="form-row">
                    <div class="form-group">
                        <label for="name">姓名 <span class="required">*</span>:</label>
                        <input type="text" id="name" name="name" value="${employee.name}" required>
                    </div>
                    <div class="form-group">
                        <label for="department">部门 <span class="required">*</span>:</label>
                        <input type="text" id="department" name="department" value="${employee.department}" required>
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <label for="position">职位 <span class="required">*</span>:</label>
                        <input type="text" id="position" name="position" value="${employee.position}" required>
                    </div>
                    <div class="form-group">
                        <label for="salary">薪资 <span class="required">*</span>:</label>
                        <input type="number" step="0.01" min="0" id="salary" name="salary" value="${employee.salary}" required>
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <label for="email">邮箱:</label>
                        <input type="email" id="email" name="email" value="${employee.email}">
                    </div>
                    <div class="form-group">
                        <label for="phone">电话:</label>
                        <input type="text" id="phone" name="phone" value="${employee.phone}">
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <label for="hireDate">入职日期 <span class="required">*</span>:</label>
                        <input type="date" id="hireDate" name="hireDate" value="<fmt:formatDate value='${employee.hireDate}' pattern='yyyy-MM-dd'/>" required>
                    </div>
                </div>

                <div class="form-actions">
                    <button type="submit" class="btn primary">更新</button>
                    <a href="../EmployeeServlet?action=list" class="btn">取消</a>
                </div>
            </form>
        </div>
    </div>
</main>

<footer>
    <p>&copy; 2023 员工信息管理系统</p>
</footer>
</body>
</html>